<template>
  <div>
    <Editor :isShowLou="false" :isShowEditSet="false" @save="save" :baseInfo="baseInfo"></Editor>
  </div>
</template>

<script setup lang="ts">
import Editor from "@/components/Editor/index.vue";
import { ref, onBeforeMount } from "vue";
import { useRoute, useRouter } from "vue-router";
import { getArtInfo, editArt, createArt } from "@/api/modules/about";
import { ElMessage } from "element-plus";
const route = useRoute();
const router = useRouter();
const baseInfo = ref({ title: "", author: "", cont: "" });

const getInfo = async () => {
  if (route.query.article_id) {
    const { data } = await getArtInfo({ id: parseInt(route.query.article_id as string) });
    baseInfo.value = data as any;
  }
};

const save = async (val: any) => {
  try {
    if (route.query.article_id) {
      await editArt({ categoryId: parseInt(route.query.id as string), ...val, id: parseInt(route.query.article_id as string) });
    } else {
      await createArt({ ...val, categoryId: parseInt(route.query.id as string) });
    }
    ElMessage.success("成功");
  } catch (error) {}

  router.back();
};

onBeforeMount(() => {
  Promise.all([getInfo()]);
});
</script>

<style></style>
